<template>
  <div id="Home">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="#e8380d">
      <van-swipe-item
        v-for="(image, index) in arr.swiperImg"
        :key="index"
        class="swiper-item"
      >
        <img v-lazy="image.imgPath" class="swiper-img" :key="index" />
        <div class="swiper-text" id="swiper-text">
          <p>{{ image.h1 }}</p>
          <p>{{ image.h2 }}</p>
        </div>
      </van-swipe-item>
    </van-swipe>
    <button @click="showPopup" class="cell">
      <van-icon name="location-o" size=".3rem" color="#FFF" />{{ $store.state.lecakePlace }}
    </button>
    <van-popup
      v-model="show"
      position="left"
      :style="{ height: '100%', width: '70%' }"
      ><div id="popup">
        <div class="header">
          <p>配送至</p>
          <p>当前定位城市:</p>
        </div>
        <div class="body">
          <div class="text">
            <a
              href="javascript:void(0);"
              v-for="(placeName, placeNameId) in placeNameList"
              :key="placeNameId"
              :class="placeNameId == activeIndex ? 'active' : ''"
              @click="placeSlide(placeNameId)"
              >{{ placeName }}</a
            >
          </div>
        </div>
        <a href="#" class="search"
          ><van-icon name="search" size=".5rem" />查询收货地址是否可配送 ></a
        >
      </div></van-popup
    >
    <div id="section">
      <div class="inner">
        <div class="left">
          <img src="../assets/ahaLogo1.png" alt="" />
          <p>尊贵礼遇享不停，升级aha会员</p>
          <p>预计可省¥358+，<a href="#" class="more">了解更多</a></p>
          <img src="../assets/ahaRights.png" alt="" />
          <a href="javascript:void(0);" class="btn">立即开通 ¥99/年</a>
        </div>
        <a href="#" class="right">
          <img src="../assets/icon_calender.png" alt="" />
          <p>06/03 超级会员日<br />爆款蛋糕低至¥128<br />*每月第一个周四</p>
        </a>
      </div>
    </div>
    <div>
      <van-swipe class="my-swipe2" :autoplay="3000" indicator-color="#e8380d">
        <van-swipe-item
          v-for="(image, index) in arr.swiperImg2"
          :key="index"
          class="swiper-item2"
        >
          <img v-lazy="image.imgPath" class="swiper-img2" :key="index" />
          <div class="swiper-text2">
            <p>{{ image.h1 }}</p>
            <p>{{ image.h2 }}</p>
            <p>{{ image.h3 }}</p>
          </div>
        </van-swipe-item>
      </van-swipe>
    </div>
    <!-- 蛋糕推荐 -->
    <div id="goodsList">
      <h2>
        <span>蛋糕推荐</span>
      </h2>
      <div class="item" v-for="(as, index) in arr.data" :key="index">
        <a href="javascript:void(0);">
          <router-link :to="'/detail/' + as.id">
            <img :src="as.imgUrl" alt="" />
          </router-link>
        </a>
        <div class="goods_desc">
          <p class="name">{{ as.h1 }}</p>
          <p class="recommend">{{ as.h2 }}</p>
        </div>
      </div>
    </div>
    <!-- 企业兑换/卡券绑定/合作专区 -->
    <div id="others">
      <a href="#" id="cake">
        <p></p>
        <p>企业兑换</p>
      </a>
      <a href="#" id="bind">
        <p></p>
        <p>卡券绑定</p>
      </a>
      <a href="#" id="bank">
        <p></p>
        <p>银行活动</p>
      </a>
    </div>
    <!-- 公司信息 -->
    <div id="lecake" style="margin-bottom: 0.6rem">
      <div class="type">
        <a href="">电脑版</a>
        <a href="">网站公告</a>
        <a href="">经营资质</a>
      </div>
      <h5>
        copyright &copy; 2010-2021&nbsp;&nbsp;诺心lecake.com版权所有<br />
        诺心食品（上海）有限公司
        <a href="#" target="_blank">&nbsp;&nbsp;沪ICP备10211730号</a>
      </h5>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "HomePage",
  data() {
    return {
      arr: [],
      placeNameList: [],
      current: 0,
      show: false,
      activeIndex: 0,
    };
  },
  created() {
    axios
      .get(
        "https://www.fastmock.site/mock/942dfbb577a74c49a06b657043b1622a/lecake/lecakeHome"
      )
      .then((res) => {
        this.arr = res.data;
      });
    axios
      .get(
        "https://www.fastmock.site/mock/942dfbb577a74c49a06b657043b1622a/lecake/generalData"
      )
      .then((res) => {
        this.placeNameList = res.data.placeNameList;
        this.showPlace()
      });
    
  },
  methods: {
    showPopup() {
      this.show = true;
    },
    onChange(index) {
      this.current = index;
    },
    placeSlide(index) {
      this.activeIndex = index;
      localStorage.setItem("place", JSON.stringify(this.placeNameList[index]));
      // 更新状态管理器的所在地
      this.$store.commit('setPlace', this.placeNameList[index]);
    },
    showPlace() {
      this.placeNameList.forEach((item, index) => {
        if (item == this.$store.state.lecakePlace) {
          this.activeIndex = index;
        }
      });
    },
  },
};
</script>

<style  scoped="scoped">
.my-swipe .van-swipe-item {
  line-height: 0;
  text-align: center;
}
.swiper-item {
  position: relative;
}
.swiper-img {
  width: 100%;
  height: 10rem;
}
.swiper-item .swiper-text {
  position: absolute;
  bottom: 0.625rem;
  left: 0.3125rem;
  text-align: left;
  padding-left: 0.25rem;
}

.swiper-item .swiper-text::before {
  content: "";
  position: absolute;
  left: 0;
  top: 15%;
  width: 0.15rem;
  height: 0.5rem;
  background: #e8380d;
}

.swiper-item:nth-of-type(1) {
  color: #dd566d;
}
.swiper-item:nth-of-type(2) {
  color: #c81123;
}
.swiper-item:nth-of-type(3) {
  color: #fff;
}
.swiper-item:nth-of-type(4) {
  color: #28a6e3;
}

.swiper-text p:nth-of-type(1) {
  font-size: 0.45rem;
  font-weight: 600;
}
.swiper-text p:nth-of-type(2) {
  font-size: 0.375rem;
  font-weight: 600;
}
.swiper-item2 {
  position: relative;
}
.my-swipe2 {
  width: 100%;
  height: 2.9rem;
}
.swiper-img2 {
  width: 100%;
  height: 100%;
}
.swiper-item2 .swiper-text2 {
  position: absolute;
  bottom: 0.625rem;
  left: 0.3125rem;
  text-align: left;
  line-height: 0.1rem;
}
.swiper-text2 p:nth-of-type(1) {
  font-size: 0.4rem;
  font-weight: 600;
}
.swiper-text2 p:nth-of-type(2) {
  font-size: 0.3rem;
}
.swiper-text2 p:nth-of-type(3) {
  font-size: 0.3rem;
}
.swiper-item2:nth-of-type(1) {
  color: #461103;
}
.swiper-item2:nth-of-type(2) {
  color: #ff4568;
}
.cell {
  border: none;
  position: absolute;
  top: 0.3125rem;
  left: 0.3125rem;
  background: #999;
  font-size: 0.25rem;
  color: #fff;
  padding: 0.0625rem 0.125rem;
  border-radius: 0.625rem;
}
.vanCell,
.van-icon {
  vertical-align: middle;
}
#popup {
  padding: 0.1875rem 0.375rem;
  background: #ffffff;
  overflow: hidden;
}
.header {
  color: #3e3e3e;
  line-height: 0.3125rem;
}
.header p:nth-child(odd) {
  font-size: 0.375rem;
}
.header p:nth-child(even) {
  font-size: 0.25rem;
}
.body {
  padding: 0.3125rem 0.5rem;
  border-top: 1px solid #e0dcd1;
  border-bottom: 1px solid #e0dcd1;
}
.body .text {
  display: flex;
  flex-direction: column;
}
a:hover {
  text-decoration: none;
}
.body .text a {
  display: inline-block;
  width: 100%;
  font-size: 0.3rem;
  line-height: 0.7rem;
  color: #3e3e3e;
  text-decoration: none;
  position: relative;
  padding-left: 0.1rem;
}
.active::before {
  content: "";
  height: 0.2rem;
  width: 0.06rem;
  background: #c81123;
  position: absolute;
  top: 35%;
  left: -0.1rem;
}
.search {
  font-size: 0.25rem;
  color: #3e3e3e;
  text-decoration: none;
}
#section {
  background-color: #fff;
  padding: 0.3125rem 0.1875rem;
  display: inline-block;
}
.inner {
  width: 7.144rem;
  display: inline-block;
}
.left {
  float: left;
  width: 60%;
}
.left img:nth-of-type(1) {
  height: 0.5rem;
  display: block;
  margin-bottom: 0.3rem;
}
.left p {
  font-size: 0.25rem;
  line-height: 0.125rem;
}
.more {
  color: #cea461;
  text-decoration: underline;
}
.left img:nth-of-type(2) {
  height: 1.16rem;
  display: block;
}
.btn {
  display: inline-block;
  width: 2rem;
  height: 0.56rem;
  background: #cda366;
  line-height: 0.56rem;
  padding: 0 0.32rem;
  color: #ffffff;
  font-size: 0.26rem;
}
.right {
  float: right;
  width: 40%;
  color: #c8a76f;
}
.right img {
  display: block;
  height: 0.35rem;
  margin-top: 0.1rem;
}
.right p {
  font-size: 0.28rem;
  margin: 0;
}
#goodList {
  margin: 0;
  padding: 0;
}
#goodsList h2 {
  margin: 0;
  padding: 0;
  width: 100%;
  display: inline-block;
  text-align: center;
  font-size: 0.3rem;
  font-weight: 600;
  position: relative;
}
#goodsList h2 span::before {
  content: "-";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%) translateX(2.9rem);
}
#goodsList h2 span::after {
  content: "-";
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%) translateX(-2.9rem);
}
#others {
  padding: 0.3rem 0.4rem;
  background-color: #fff;
  display: flex;
}
#others a {
  width: 33.33%;
  text-align: center;
  color: #3e3e3e;
  font-size: 0.25rem;
  font-weight: 600;
}
#others a p:nth-of-type(1) {
  width: 0.6rem;
  height: 0.6rem;
  margin-left: 37%;
}
#others #cake p:nth-of-type(1) {
  background: url("../assets/icons_5.png") no-repeat center;
  background-size: 8rem 8rem;
  background-position: -3.3rem 0;
}
#others #bind p:nth-of-type(1) {
  background: url("../assets/icons_5.png") no-repeat center;
  background-size: 8rem 8rem;
  background-position: -4.1rem 0;
}
#others #bank p:nth-of-type(1) {
  background: url("../assets/icons_5.png") no-repeat center;
  background-size: 8rem 8rem;
  background-position: -4.9rem 0;
}
#lecake {
  text-align: center;
  background-color: #e6e6e6;
  padding: 0.44rem 0 0.16rem;
  font-size: 0.24rem;
}
#lecake .type {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: center;
  line-height: 0.42rem;
}
#lecake .type a {
  display: block;
  width: 1.2rem;
  height: 0.45rem;
  border: 1px solid #4a3234;
  color: #3e3e3e;
  padding: 0 0.06rem;
}

#lecake .type a:nth-of-type(2) {
  margin: 0 0.2rem 0 0.2rem;
  padding: 0 0.1rem;
}
#lecake .type a:nth-of-type(3) {
  padding: 0 0.1rem;
}
#lecake h5 {
  color: #bababa;
}
#lecake h5 a {
  color: #bababa;
}
.item {
  position: relative;
}
.item a {
  display: block;
  text-decoration: none;
}
.item a img {
  width: 100%;
  height: 100%;
}
.item .goods_desc {
  position: absolute;
  top: 0.2rem;
  left: 0.3rem;
  color: #3e3e3e;
  line-height: 0.08rem;
  padding-left: 0.15rem;
}
.item .goods_desc::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.2rem;
  width: 0.08rem;
  height: 0.3rem;
  background: #e8380d;
}
.item .goods_desc .name {
  font-size: 0.3rem;
}
.item .goods_desc .recommend {
  font-size: 0.2rem;
}
</style>